var t = getApp();

Page({
  data: {
    textareaHeight: 250,
    currenttype: 1,
    saidtype: 1,
    patientIdArr: [],
    teamList: [],
    monentIdea: "",
    monentIdeaText: "",
    imgArr: [],
    imgPath: "",
    showFlag: !1,
    propagandaId: "",
    sendFalg: !0,
    gotoUrl: "/hyb_yl/backstageFollowUp/pages/ChangePatient/ChangePatient",
    time: null,
    data_arr: [],
  },
  onLoad: function(options) {
    var that = this
    var uniacid = t.siteInfo.uniacid;
    var zid = options.zid
    if (options.arr) {
      var arr = JSON.parse(options.arr)
      that.setData({
        arr: arr,
        uniacid: uniacid,
        zid: zid
      })
    }
    if (options.hjlistinfo) {
      var hjlistinfo = JSON.parse(options.hjlistinfo)
      if (options.saidtype) {
        that.setData({
          saidtype: options.saidtype,
          hjlistinfo: hjlistinfo,
          zid: zid,
          uniacid: uniacid,
        })
      }
    }
    t.util.request({
      'url': 'entry/wxapp/url',
      success: function(res) {
        console.log(res)
        that.setData({
          url: res.data
        })
      },
    })
  },
  onReady: function() {},
  onShow: function() {
    var that = this
    let pages = getCurrentPages();
    let currPage = pages[pages.length - 1];
    //console.log(currPage.data.hjlistinfo)
    if (currPage.data.hjlistinfo !== undefined) {
      that.setData({ //将携带的参数赋值
        hjlistinfo: currPage.data.hjlistinfo,
        ystype: 1
      });
    }
    var arr1 = wx.getStorageSync('patientList')
    console.log(arr1.weifenzu)
    if (arr1.weifenzu) {
      that.setData({ //将携带的参数赋值
        arr: arr1.weifenzu
      });
    }
  },
  onHide: function() {},
  onUnload: function() {

  },

  touchend: function(t) {
    a && (this.data.flagBoo = !0, a.stop(), this.setData({
      voiceFlag: !1
    }));
  },
  againBtn: function() {
    this.setData({
      soundFlag: !1,
      tempFilePath: [],
      time: null
    });
  },
  toPlay: function() {
    n ? (n.src = this.data.tempFilePath[0], this.data.playFlag ? n.stop() : n.play()) : wx.showModal({
      content: "您当前微信版本过低，暂不支持语音功能，请更新微信版本后重试",
      showCancel: !1,
      confirmColor: "#3b4ca9",
      confirmText: "我知道了"
    });
  },
  tapSaidType: function(t) {
    console.log(t)
    t.target.dataset.saidtype != this.data.saidtype && (this.setData({
      saidtype: t.target.dataset.saidtype
    }), 2 == this.data.saidtype ? this.setData({
      imgArr: []
    }) : (this.setData({
      propagandaId: "",
      currentSaid: "",
      hjlistinfo: ""
    }), wx.removeStorageSync("currentSaid")));
  },
  getText: function(t) {
    this.setData({
      ystext: t.detail.value
    });
  },
  bindlinechange: function(t) {
    console.log(t), t.detail.heightRpx > 250 ? this.setData({
      textareaHeight: t.detail.heightRpx
    }) : this.setData({
      textareaHeight: 250
    });
  },
  chooseImage: function() {
    var t = this;
    wx.chooseImage({
      count: 9,
      sizeType: ["original", "compressed"],
      sourceType: ["album", "camera"],
      success: function(a) {
        console.log(a);
        for (var e = a.tempFilePaths, n = 0; n < e.length && 9 != t.data.imgArr.length; n++) t.data.imgArr.push(e[n]);
        9 == t.data.imgArr.length && t.setData({
          addImgFlag: !0
        }), t.setData({
          imgArr: t.data.imgArr
        });
      }
    });
  },
  delImage: function(t) {
    console.log(t), this.data.imgArr.splice(t.target.dataset.index, 1), this.data.imgArr.length < 9 && this.setData({
      addImgFlag: !1
    }), this.setData({
      imgArr: this.data.imgArr
    }), console.log(this.data.imgArr);
  },
  previewImage: function(t) {
    console.log(t);
    var a = this;
    this.setData({
      showFlag: !0
    }), wx.previewImage({
      current: t.target.dataset.url,
      urls: a.data.imgArr
    });
  },
  tapSaidTextType: function(t) {
    console.log(t), t.target.dataset.currenttype != this.data.currenttype && (1 == t.target.dataset.currenttype && n.stop(),
      this.setData({
        currenttype: t.target.dataset.currenttype,
        soundFlag: !1,
        tempFilePath: [],
        time: null,
        monentIdeaText: ""
      }));
  },
  publishBtn: function() {
    var that = this;
    if (that.data.arr.length <= 0) wx.showToast({
      title: "请先选择患者",
      icon: "none",
      duration: 2e3
    });
    else {
      var ystext = that.data.ystext
      var user = that.data.arr
      console.log(that.data.ystype)
      if (that.data.ystype == 1) {
        console.log('123')
        var hid = that.data.hjlistinfo.h_id
      } else {
        var hid = 0
        console.log('qwe')
      }
      var hj_tex = this.data.monentIdeaText
      this.upload();
      var data_arr = that.data.data_arr
      wx.showToast({
        title: '发表中...',
        icon: "loading",
        duration: 3000,
      })
      setTimeout(function() {
        console.log(data_arr)
        t.util.request({
          'url': 'entry/wxapp/Saveyishuo',
          data: {
            zid: that.data.zid,
            hid: hid,
            yspic: data_arr,
            ystext: ystext,
            user: user,
            op: 'post'
          },
          success: function(res) {
            console.log(res)
            wx.showToast({
              title: '发表成功',
              icon: "none",
              duration: 1e3,
              success: function() {
                setTimeout(function(){
                  wx.navigateBack({
                    delta: 1
                  })
                },2000)
              }
            })
          },
          fail: function(err) {
            console.log(err)
          },
        })
      }, 3000)
    }
  },
  upload: function() {
    var that = this
    var uniacid = that.data.uniacid
    var data_arr = that.data.data_arr;
    console.log(data_arr)
    console.log(this.data.imgArr)
    for (var i = 0; i < this.data.imgArr.length; i++) {
      wx.uploadFile({
        url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Upload&m=hyb_yl',
        filePath: that.data.imgArr[i],
        name: 'upfile',
        formData: {},
        success: function(res) {
          console.log(res)
          data_arr.push(res.data)
          that.setData({
            data_arr: data_arr
          })
        }
      })
    }
  },
  send: function(a) {
    var e = this;

  },
  sendVoice: function(a) {
    var e = this;
    wx.uploadFile({
      url: t.globalData.dic + "doctor/said/upload",
      method: "POST",
      header: {
        "content-type": "multipart/form-data"
      },
      filePath: this.data.tempFilePath[0],
      name: "file",
      formData: {
        token: e.data.token
      },
      success: function(t) {
        console.log(t), 200 == t.statusCode && (e.data.monentIdea = JSON.parse(t.data).data,
          e.send(a));
      }
    });
  }
});

var a = wx.getRecorderManager ? wx.getRecorderManager() : null,
  e = {
    sampleRate: 44100,
    numberOfChannels: 1,
    encodeBitRate: 192e3,
    format: "mp3",
    frameSize: 50
  },
  n = wx.createInnerAudioContext ? wx.createInnerAudioContext() : null;